package annotation1;

import java.lang.reflect.Field;
import java.util.ResourceBundle;

/**
 * 来判断被HasId注解的user类有没有int id
 */
public class Test {

    public static void main(String[] args) throws ClassNotFoundException {
        Class c = Class.forName(ResourceBundle.getBundle("classinfo2").getString("className4"));

        if (c.isAnnotationPresent(HasId.class)){
            Field[] fields = c.getDeclaredFields();
            boolean isRight = false;//判断标记

            //遍历属性进行属性名和属性类型的判断
            for (Field f:fields){

                if ("id".equals(f.getName()) && "int".equals(f.getType().getSimpleName())){
                    isRight = true;
                    break;
                }
            }

            //判断是否合法
            if (!isRight){
                throw new NotHasIdException("被Id注解修饰的类中没有int类型的id属性");
            }
        }

    }
}
